package com.baaio.conn;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import com.baaio.conn.Interface.BaaioConn;

/**
 * 动态代理类
 *
 */
public class BaaioProxy implements InvocationHandler
{
	private Object object;
	
	public BaaioConn getBaaioConn()
	{
		BaaioConnBase bci = new BaaioConnBase();
		this.object = bci;
		BaaioConn t = (BaaioConn)Proxy.newProxyInstance(bci.getClass().getClassLoader(),bci.getClass().getInterfaces(),this);
		return t;
		
	}
	
	public BaaioConn getBaaioConn(String tbName)
	{
		BaaioConnBase bci = new BaaioConnBase(tbName);
		this.object = bci;
		BaaioConn t = (BaaioConn)Proxy.newProxyInstance(bci.getClass().getClassLoader(),bci.getClass().getInterfaces(),this);

		return t;
		
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable
	{

		Object result = method.invoke(object,args);
		return result;
	}
	
}
